package com.itheima.d7_stream;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class StreamTest4 {
    public static void main(String[] args) {
        List<Student> students = new ArrayList<>();
        Student s1 = new Student("张三", 23,181);
        Student s2 = new Student("张二", 25,180);
        Student s3 = new Student("李四", 24,182);
        Collections.addAll(students, s1, s2, s3);

        System.out.println(students.stream().filter(s -> s.getHeight() > 180).count());
        System.out.println("******");

        System.out.println(students.stream().max((o1, o2) -> Double.compare(o1.getHeight(), o2.getHeight())).get());
        System.out.println("******");
        System.out.println(students.stream().min((o1, o2) -> Double.compare(o1.getHeight(), o2.getHeight())).get());
        System.out.println("******");
        students.stream().filter(a->a.getHeight()>180).collect(Collectors.toList()).forEach(System.out::println);
        System.out.println("******");
        students.stream().filter(a->a.getHeight()>180).collect(Collectors.toSet()).forEach(System.out::println);
        System.out.println("******");
        System.out.println(students.stream().filter(b -> b.getHeight() > 180)
                        .distinct().collect(Collectors.toMap(c -> c.getName(), c -> c.getHeight())));

        System.out.println("******");

        Student[] students1 = students.stream().filter(b -> b.getHeight() > 180).toArray(len -> new Student[len]);
        System.out.println(Arrays.toString(students1));

    }}
